

function populateProfile() {
    var who = JSON.parse(localStorage.getItem("loggedinUser"));
    var users = JSON.parse(localStorage.getItem("users"));

    //find the person who is logged in
    const user = users.find(u => u.email === who["email"]);

    document.getElementById('nameInput').value = user['name'];
    document.getElementById('locationInput').value = user['location'];
    document.getElementById('emailInput').value = user['email'];
    document.getElementById('weightInput').value = user['weight'];

}
populateProfile();

function editProfile() {
    document.getElementById('personalInfoFields').disabled = false;
}
function saveProfile() {
    var who = JSON.parse(localStorage.getItem("loggedinUser"));
    var users = JSON.parse(localStorage.getItem("users"));

    //find the person who is logged in
    const user = users.find(u => u.email === who["email"]);
    user['name'] = document.getElementById('nameInput').value;
    user['location'] = document.getElementById('locationInput').value;
    user['email'] = document.getElementById('emailInput').value;
    user['weight'] = document.getElementById('weightInput').value;

    localStorage.setItem("loggedinUser", JSON.stringify(user));
    localStorage.setItem("users", JSON.stringify(users));

    alert('User Data Saved');
    document.getElementById('personalInfoFields').disabled = true;
}
